<template>
  <div class="contain">
    <!-- 已经登陆  -->
    <div class="head-login" v-if="$store.state.token">
      <div class="info-user">
        <div class="pho">
          <img :src="user.photo" />
          <h3>{{user.name}}</h3>
        </div>
        <button class="van-button" @click="$router.push('/xiugai')">编辑资料</button>
      </div>
      <ul class="guanz-info">
        <li>
          <div class="con">
            <h3>8</h3>
            <p>头条</p>
          </div>
        </li>
        <li>
          <div class="con">
            <h3>66</h3>
            <p>关注</p>
          </div>
        </li>
        <li>
          <div class="con">
            <h3>88</h3>
            <p>粉丝</p>
          </div>
        </li>
        <li>
          <div class="con">
            <h3>88</h3>
            <p>获赞</p>
          </div>
        </li>
      </ul>
    </div>   
     <!-- 未登陆  -->
    <div class="header" v-else>
      <div class="no-login" @click="$router.push('/login')">
        <img src="~@/assets/mobile.png" />
        <p>登陆 / 注册</p>
      </div>
    </div>
    <!-- 宫格 -->
    <van-grid clickable :column-num="2" class="gongge">
        <van-grid-item icon="home-o" text="路由跳转">
            <i slot="icon" class="iconfont icon-shoucang"></i>
            <span slot="text" class="txt">收藏</span>
        </van-grid-item>
         <van-grid-item icon="home-o" text="路由跳转">
             <i slot="icon" class="iconfont icon-lishi"></i>
            <span slot="text" class="txt">历史</span>
        </van-grid-item>
    </van-grid>
    <!-- 单元格 -->
    <van-cell-group border>
      <van-cell center value="消息通知" is-link />
      <van-cell center value="小智同学" is-link />
    </van-cell-group>
    <van-cell class="exit" clickable v-if="$store.state.token" >
    <!-- 使用 title 插槽来自定义标题 -->
    <template #title >
        <span class="custom-title" @click="exit">退出登录</span>
    </template>
    </van-cell>
 </div>
 
</template>
<script>
import { userinfo } from '@/api/user.js'
export default {
  data:function(){
    return {
      user:[]
    }
  },
  methods:{
    exit(){
      this.$dialog.confirm({
        title: '退出提示',
        message: '确定退出'
      })
        .then(() => {
          this.$store.commit('local',null)
        })
        .catch(() => {
          // on cancel
        })       
    },
    async userinfo(){
      if (this.$store.state.token === null){
        console.log('没有登录')
      } else {
        const usertxt = await userinfo()
        this.user = usertxt.data.data
        console.log(this.user)
      }      
    }
  },
  mounted(){
    this.userinfo()
  }
}
</script>
<style lang="less">
.header {
  height: 401px;
  background: url('~@/assets/banner.png') no-repeat;
  background-size: cover;
  display: flex;
  justify-content: center;
  align-items: center;
  .no-login {
    img {
      width: 132px;
      height: 132px;
      display: block;
      margin-bottom: 15px;
    }
    p {
      font-size: 28px;
      color: #ffffff;
    }
  }
}
.head-login {
  height: 401px;
  background: url('~@/assets/banner.png') no-repeat;
  background-size: cover;
  padding: 100px 33px 0px;
  box-sizing: border-box;
  .info-user {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 55px;
    .pho {
        display: flex;
        flex-direction: row;
        align-items: center;
      img {
        display: block;
        width: 132px;
        height: 132px;
        border-radius: 50%;
        margin-right: 22px;
      }
      h3 {
        font-size: 30px;
        color: #ffffff;
        font-weight: normal;
      }
    }
    .van-button{
        width: 116px;
        height: 33px;
        background: #ffffff;
        border-radius: 16px;
        font-size: 20px;
        color: #666666;
        border: none;
    }
  }
  .guanz-info {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    .con {
      display: flex;
      flex-direction: column;

      color: #ffffff;
      h3 {
        font-size: 36px;
        margin-bottom: 5px;
        font-weight: normal;
      }
      p {
        font-size: 23px;
        font-weight: normal;
      }
    }
  }

}
// 宫格
.gongge{
    margin-bottom: 9px;
    .icon-shoucang{
        font-size: 45px;
        color: #eb5253;
        margin-bottom: 16px;
    }
    .icon-lishi{
        font-size: 45px;
        color: #ff9d1d;
        margin-bottom: 16px;
    }
    .txt{
        font-size: 28px;
        color: #333333;
    }
}

.van-cell__value {
  line-height: 56px;
}
// 退出登陆
.exit{  
    margin-top: 9px;
    font-size: 30px;
    color: #d86262;
    .custom-title{
      text-align: center;
    }
}
</style>
